/* $Id: AdminClientCompanyReviewDelegateImpl.java 
 * Copyright (C) 2011, TRAKHEES
 *  
 * Revision History
 *
 * Date  			Author 		    	Remarks
 * ---------------------------------------------------------------------------------
 *
 */
package ae.pcfc.etks.online.common.delegate.provider;

import ae.pcfc.etks.online.common.delegate.AdminClientCompanyReviewDelegate;
import ae.pcfc.etks.online.common.exception.AdminWorkflowException;
import ae.pcfc.etks.online.common.facade.AdminClientCompanyReviewFacade;
import ae.pcfc.etks.online.common.vo.AdminApprovalVO;
import ae.pcfc.etks.online.common.vo.ClientCompanyVO;
import ae.pcfc.etks.online.wf.service.client.provider.ClientCompanyAdminWFImpl;
import ae.pcfc.etks.online.wf.service.client.vo.ClientAdminCompleteStepVO;

public class AdminClientCompanyReviewDelegateImpl extends BaseDelegateImpl implements AdminClientCompanyReviewDelegate{

	/*
	 * Here we coordinate between the Facade service which handles DB entities
	 * and the WF both will be looked up with service locator normally we will
	 * have 1-1 relationship between the delegate and the facade and 1-1
	 * relationship between the delegate and the WF service which means for
	 * CompanyRegistrationDelegate there will be ClientRegistrationFacade &
	 * CompanyRegistrationWF validations that related to DB vs WF are maintained
	 * here ie user cannot issue a new request while he already have a request
	 * in the wf Exception are translated in to business exception
	 */
	public AdminClientCompanyReviewDelegateImpl(){
		
	}
	
	/**
	 * getClientCompanyByApplicationId
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.AdminClientCompanyReviewDelegate#getClientCompanyByApplicationId(java.lang.Long)
	 * 
	 */
	public ClientCompanyVO getClientCompanyByApplicationId(Long applicationId) {
		
		return serviceLocator.getFacadeService(AdminClientCompanyReviewFacade.class).getClientCompanyByApplicationId(applicationId);		
	
	}

	/**
	 * reviewRegisterClientCompany
	 * 
	 * @see ae.pcfc.etks.online.common.delegate.AdminClientCompanyReviewDelegate#reviewRegisterClientCompany(ae.pcfc.etks.online.common.vo.AdminApprovalVO, ae.pcfc.etks.online.common.vo.ClientCompanyVO)
	 * 
	 */
	public void reviewRegisterClientCompany(AdminApprovalVO adminApprovalVO, ClientCompanyVO clientCompanyVO) {
    	AdminClientCompanyReviewFacade adminClientCompanyReviewFacade = serviceLocator.getFacadeService(AdminClientCompanyReviewFacade.class);
    	ClientAdminCompleteStepVO completeStepVO = adminClientCompanyReviewFacade.reviewRegisterClientCompany(adminApprovalVO, clientCompanyVO);
 	    try{
	    	ClientCompanyAdminWFImpl clientCompanyAdminWFImpl =serviceLocator.getWorkflowService(ClientCompanyAdminWFImpl.class);
	    	clientCompanyAdminWFImpl.completeClientAdminWFStep(completeStepVO);
 	    }catch(Throwable t){
 	    	adminClientCompanyReviewFacade.undoReviewRegisterClientCompany(adminApprovalVO, clientCompanyVO);
 	    	throw new AdminWorkflowException(t);
 	    }
	}

}
